<?php
//require section
require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . '/api_about_us.php';
require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'ckeditor.php';

$title = 'Admin Panel';
?>

<!DOCTYPE html>
<html>
    <head>
        <?php
        require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php';
        ?>
    </head>
    <body>
        <div class="uk-container uk-container-center uk-margin-top">
            <?php
            require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'menu.php';
            
            $about_us = api_about_us::get_about_us();
            $title = $about_us['title'];
            $content = $about_us['content'];
            if (!empty($_POST)) {
                if (!empty($_POST['txt_title'])) {
                    $title = $_POST['txt_title'];
                }
                if (!empty($_POST['txt_content'])) {
                    $content = $_POST['txt_content'];
                }
                if (api_about_us::set_about_us($title, $content)) {
                    $success_info = "Đã lưu thành công.";
                }
            }
            
            ?>

            <section class="ts-body-container uk-panel uk-panel-box ts-padding-large">
                <h2><strong>Thông Tin Trang Giới Thiệu</strong></h2>
                <?php 
                if (!empty($error_show)) {?>
                <div class="error">Lỗi: <?php echo $error_show; ?></div>
                <?php
                } else if (!empty($success_info)) {?>
                <div class="success"><?php echo $success_info; ?></div>
                <?php
                }?>
                <form action="?" method="POST" name="form_save">
                <table class="ts-table">
                    <tr>
                        <th><label for="txt_title">Tiêu đề:<span class="ts-alert">*</span></label></th>
                        <td><input name="txt_title" class="uk-form-width-large" value="<?php echo $title; ?>" type="text" placeholder="Title" required></td>
                    </tr>
                    <tr>
                        <th><label for="txt_phone">Nội dung:<span class="ts-alert">*</span></label></th>
                        <td><textarea class="ckeditor" name="txt_content" placeholder="Content" class="form-control" rows="3"><?php echo $content; ?></textarea></td>
                    </tr>
                    <tr>
                        <th></th>
                        <td><input type="submit" name="btn_submit" value="Lưu" class="uk-button uk-button-large uk-button-primary"></td>
                    </tr>
                </table>
                </form>
            </section>
            
            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
            ?>
        </div>
    </body>
</html>